package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.CurrentUser;
import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.vo.request.DeviceSearchVo;
import com.zhijian.medical.entity.vo.request.MedicalDeviceSearchVo;
import com.zhijian.medical.entity.vo.request.StoneSearchVo;
import com.zhijian.medical.entity.vo.response.DeviceVo;
import com.zhijian.medical.entity.vo.response.HarmfulVo;
import com.zhijian.medical.entity.vo.response.MedicalDeviceVo;
import com.zhijian.medical.entity.vo.response.StoneVo;
import com.zhijian.medical.service.SensorService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@Controller
@Api(tags = "传感器设备")
public class SensorController {


    @Autowired
    private SensorService sensorService;


    /**
     * 传感器列表编辑
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("sensor/edit")
    @ApiOperation("传感器列表编辑")
    public boolean editByCondition(@CurrentUser @ApiIgnore PersonDto personDto,
                                                   @RequestBody(required = false) MedicalDeviceSearchVo param) {
        if (param == null)
            param = MedicalDeviceSearchVo.builder().build();
        //todo 暂时注释掉
//      param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return sensorService.editByCondition(param);
    }


    /**
     * 传感器列表删除
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("sensor/delete")
    @ApiOperation("传感器列表删除")
    public boolean deleteByCondition(@CurrentUser @ApiIgnore PersonDto personDto,
                                   @RequestBody(required = false) MedicalDeviceSearchVo param) {
        if (param == null)
            param = MedicalDeviceSearchVo.builder().build();
        //todo 暂时注释掉
//      param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return sensorService.deleteByCondition(param);
    }


    /**
     * 传感器列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("sensor/page")
    @ApiOperation("传感器列表查询")
    public Page<MedicalDeviceVo> selectByCondition(@CurrentUser @ApiIgnore PersonDto personDto,
                                                   @RequestBody(required = false) MedicalDeviceSearchVo param) {
        if (param == null)
            param = MedicalDeviceSearchVo.builder().build();
        //todo 暂时注释掉
//      param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        param.setDeviceType("1");
        return sensorService.selectPage(param);
    }


    /**
     * 各类传感器列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("every/device/page")
    @ApiOperation("传感器列表查询")
    public Page<MedicalDeviceVo> selectEveryByCondition(@CurrentUser @ApiIgnore PersonDto personDto,
                                                   @RequestBody(required = false) MedicalDeviceSearchVo param) {
        if (param == null)
            param = MedicalDeviceSearchVo.builder().build();
        //todo 暂时注释掉
//      param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return sensorService.selectEveryPage(param);
    }

    /**
     * 各类传感器列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("stone/page")
    @ApiOperation("传感器列表查询")
    public Page<StoneVo> selectStoneByCondition(@CurrentUser @ApiIgnore PersonDto personDto,
                                                @RequestBody(required = false) StoneSearchVo param) {
        if (param == null)
            param = StoneSearchVo.builder().build();
        //todo 暂时注释掉
//      param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return sensorService.selectStonePage(param);
    }


    /**
     * 详情内容
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("sensor/page/details")
    @ApiOperation("详情内容")
    public Page<HarmfulVo> selectByDetails(@CurrentUser @ApiIgnore PersonDto personDto,
                                           @RequestBody(required = false) MedicalDeviceSearchVo param) {
        if (param == null)
            param = MedicalDeviceSearchVo.builder().build();
        //todo 暂时注释掉
//        param.setGroupIds(personDto.getGroupIds());
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return sensorService.selectByDetails(param);
    }
}
